package com.ssy.system.config;

import com.ssy.system.quartz.RegisterQuartz;
import org.quartz.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author sunshuaiyong
 * @ClassName QuartzConfig
 * @description: 定时任务配置类
 * @date 2022/4/14 14:28
 */
@Configuration
public class QuartzConfig {

    @Bean
    public JobDetail teatQuartzDetail() {
        return JobBuilder.newJob(RegisterQuartz.class).withIdentity("RegisterQuartz").storeDurably().build();
    }

    @Bean
    public Trigger testQuartzTrigger() {
        SimpleScheduleBuilder scheduleBuilder = SimpleScheduleBuilder.simpleSchedule()
                .withIntervalInSeconds(86400)  //设置时间周期单位秒  默认1天
                .repeatForever();
        return TriggerBuilder.newTrigger().forJob(teatQuartzDetail())
                .withIdentity("RegisterQuartz")
                .withSchedule(scheduleBuilder)
                .build();
    }

}
